$(function() {
  $(".nav.navbar-nav").children(":eq(1)").addClass("active").siblings(".active").removeClass("active");
});
$(function() {
  var chartc = echarts.init($("#countchart").get(0));
  var chartm = echarts.init($("#minerchart").get(0));
  var chartl = echarts.init($("#luckchart").get(0));
  var chartd = echarts.init($("#diffchart").get(0));
  var ct = "";
  if(coinType) {
    ct = coinType.toLowerCase();
  }
  var option = {
    tooltip: {
      trigger: 'axis'
    },
    title: {
      text: '',
      left: 0,
      top: -5,
      textStyle: {
        fontWeight: 'normal',
        fontSize: 14
      }
    },
    grid: {
      left: '75',
      right: '0',
      top: '20',
      bottom: '40'
    },
    legend: {
      icon: 'rect',
      data: [],
      textStyle: {
        fontSize: 12
      }
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: [],
      axisTick: {
        show: true,
        interval: 4
      },
      axisLabel: {
        interval: 4
      }
    },
    yAxis: {
      type: 'value',
      position: 'left',
      animation: true,
      scale: true
    },
    series: [{
      name: '',
      type: 'line',
      smooth: true,
      barMaxWidth: '20',
      areaStyle: {normal: {}},
      data: [],
      itemStyle: {
        normal: {
          color: '#5555FF'
        }
      }
    }]
  };
  var optionc = $.extend(true, {}, option);
  var optionm = $.extend(true, {}, option);
  var optionl = $.extend(true, {}, option);
  var optiond = $.extend(true, {}, option);
  optionc.title.text = "单位(MH)";
  optiond.title.text = "单位(GH)";
  optionc.series[0].itemStyle.normal.color = "#5555FF";
  optionm.series[0].itemStyle.normal.color = "#003333";
  optionl.series[0].itemStyle.normal.color = "#CC3333";
  optiond.series[0].itemStyle.normal.color = "#AA7700";
  optionc.series[0].name = "总算力";
  optionm.series[0].name = "矿工数";
  optionl.series[0].name = "幸运值";
  optiond.series[0].name = "全网难度";
  chartc.setOption(optionc);
  chartm.setOption(optionm);
  chartl.setOption(optionl);
  chartd.setOption(optiond);
  $.get("http://stat-history.poolgpu.com:18081/history/" + ct + "?pageNum=0&pageSize=31", function(data) {
    var resdata = data.data;
    resdata.reverse();
    var rez = {
      st: [[], [], [], []],
      label: []
    };
    resdata.forEach(function(item, idx) {
      rez.label.push(dateFormat(item.timeStamp*1000, "MM-dd hh:mm"));
      rez.st[0].push(item.luckValue);
      rez.st[1].push(item.minerNumber);
      rez.st[2].push(((item.totalHashrate)/1000000).toFixed(2));
      rez.st[3].push(Math.round(item.networkDifficulty/(Math.pow(10, 9))));
    });
    chartc.setOption({
      xAxis: {
        data: rez.label
      },
      series: [
          {
              data: rez.st[2]
          }
      ]
    });
    chartm.setOption({
      xAxis: {
        data: rez.label
      },
      series: [
          {
              data: rez.st[1]
          }
      ]
    });
    chartl.setOption({
      xAxis: {
        data: rez.label
      },
      series: [
          {
              data: rez.st[0]
          }
      ]
    });
    chartd.setOption({
      xAxis: {
        data: rez.label
      },
      series: [
          {
              data: rez.st[3]
          }
      ]
    });
  })
});

function replaceHeaderInfo(txt) {
  if (txt.indexOf("day") > 0) {
    txt = txt.replace("day", "天")
  } else if (txt.indexOf("week") > 0) {
    txt = txt.replace("week", "周")
  } else if (txt.indexOf("month") > 0) {
    txt = txt.replace("month", "月")
  }
  return txt
}
